import * as API_LIST from '../../apis/dialog.js'
import Apis from '../../apis/roomPlan'
import { findDOMNode } from "react-dom";
import { toJS } from 'mobx';
import { Tooltip, Spin, Modal, Popover, Button, Carousel, Row  } from 'antd'
import moment from 'moment'
import { WeaInputSearch, WeaAlertPage, WeaNewScroll, WeaDragChoose, WeaDialog, WeaDateSwitch, WeaRightMenu } from 'ecCom'
import MeetingDialog from '../../public/dialog/index.js'
import RoomPlanDialog from '../../public/roomPlan/index'
import LeftSearch from './LeftSearch'
import { inject, observer } from 'mobx-react'
import { WeaTableNew } from 'comsMobx'
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const WeaTable = WeaTableNew.WeaTable
const confirm = Modal.confirm;
const errorModal = Modal.warning;

import '../../lib/wdCalendar_lang_wev8';

const i18n=window.meetingCalendarI18n;


const store = ['meetingRoomPlan', 'meetingDialog', 'meetingCalView']
@inject(...store)
@observer
class RoomPlanContainer extends React.Component {
  constructor (props) {
    super(props);
    this.state = {
      timeType: props.byWhat == '2' ? 'month' : (props.byWhat == '3' ? 'week' : 'day'),
      date: this.props.meetingCalView.isMeetingUsageBtn ? new Date() : (this.props.meetingDialog.addDate(props.meetingId) || new Date()),
      subId: props.subId,
      subName: props.subName,
      color: {},
      baseLoading: true,
      rooms: [],
      useMap: {},//key为roomid，value为使用信息
      startHour: 0,
      endHour: 23,
      duration: 0,
      roomName: '',//搜索栏
      roomLoading: true,
      pageTabKey: '',
      roomId: '',
      createObj: {},
      createVisible: false,
      previewMeetingId: '',
      roomPlanVisible: false,
      conHeight: 0,
      tabHeight: 0,
      listHeight: 280,
      dialogZIndex: 801,
      RoomPlanContainer: false,
      MeetingDialog: false,
      visible: false,
      dialogType: 'create',
      meetingId: '',
      canQuickCreate:0,
      showFastCreateDialog: false, //快速新建会议
      name: '',//快速新建会议输入框的值
      onlyFlowCreate:0,//是否只允许使用流程新建会议
      hideCreateEntry:0,//是否隐藏新建入口,只能通过流程模块新建会议
      workflowBaseIds:'',//新建会议流程使用的workflow_base对应的id
      addRequestUrlParams : '',
      requestFieldIds:{},//在从会议室使用情况新建的时候对应只有一条流程打开时候需要带出参数
      roomPlanId:'',
      roomPlanType:'',
      mrtype: props.roomPlanType || '',
      isFirst : true,
      weekStartDay: 0,
    }
  }

  componentWillMount () {
    let {roomPlanId,roomPlanType} = this.props;
    this.setState({
      roomPlanId:roomPlanId,
      roomPlanType:roomPlanType
    })
    window.moment = moment;
  }

  componentDidMount () {
    const {meetingRoomPlan} = this.props;
    Apis.getRoomReportBaseData().then((result) => {
      let {agreementColor, conflictedColor, usedColor, subname, timestart, timeend, roomConflictType,canQuickCreate} = result
      agreementColor || (agreementColor = '#FFE4C4'), conflictedColor || (conflictedColor = '#FBDFEB'), usedColor || (usedColor = '#E3F6D8')
      this.setState({
        subName: subname,
        color: {agreementColor, conflictedColor, usedColor},
        baseLoading: false,
        startHour: timestart,
        endHour: timeend,
        roomConflictType: roomConflictType,
        canQuickCreate:canQuickCreate,
        onlyFlowCreate:result.onlyFlowCreate&&result.onlyFlowCreate || 0,
        hideCreateEntry:result.hideCreateEntry&&result.hideCreateEntry || 0,
        workflowBaseIds:result.workflowBaseIds&&result.workflowBaseIds || '',
        requestFieldIds:result.requestFieldIds&&result.requestFieldIds || {},
        weekStartDay: result.weekStartDay && result.weekStartDay || 0
      })
      meetingRoomPlan.form.initFormFields(result.searchFields);
      meetingRoomPlan.searchFields = result.searchFields;
      //判断是否禁止新建
			window.eventRegister.startList("checkCreateMeeting",function(){},function(){});
    })
    this.query()
  }
  
  componentWillReceiveProps (nextProps) {
    
    if (nextProps.subId != this.props.subId) {
      this.setState({
        subId: nextProps.subId,
        subName: nextProps.subName
      }, this.query)
    }
    if (this.state.dialogZIndex != nextProps.dialogZIndex && nextProps.dialogZIndex) {
      this.setState({
        dialogZIndex: nextProps.dialogZIndex
      })
    }
  }
  
  componentDidUpdate (prevProps, prevState) {
    // 处理高度自适应问题
    let
      container = jQuery('.roomplan-container', ReactDOM.findDOMNode(this)),
      conHeight = this.props.height ? (this.props.height - 108) : container.height()
    let tab = jQuery('.room-plan-tab', container), tabHeight = tab.height()
    let
      list = jQuery('.list-container .wea-new-table', container),
      listHeader = jQuery('.ant-table-header', list),
      listBody = jQuery('.ant-table-body>table', list),
      listEmpty = jQuery('.ant-table-placeholder', list),
      listPage = jQuery('.wea-table-pagination', list),
      listContent = jQuery('.ant-table-content', list),
      listHeight
    if (listEmpty.height() != null && listEmpty.height() != 0) {
      listHeight = listContent.height() + listPage.height()
    } else {
      listHeight = listHeader.height() + listBody.height() + listPage.height()
    }
    if (conHeight !== this.state.conHeight || tabHeight !== this.state.tabHeight || listHeight !== this.state.listHeight) {
      this.setState({
        conHeight: conHeight,
        tabHeight: tabHeight,
        listHeight: listHeight
      })
    }
  }
  
  componentWillUnmount(){
    const {resetFormParams} =this.props.meetingRoomPlan
    resetFormParams()

  }
  
  /*修改选择的时间类型则进行查询*/
  /*周月日采用组件 这个没用了 */
  changeTimeType (timeType) {
    this.setState({
      timeType: timeType
    }, this.query)
  }
  mrtypeChange = (value) =>{
    const {meetingRoomPlan} = this.props;
    this.setState({
      mrtype : value
    })
    meetingRoomPlan.advanceSearchParams = {...meetingRoomPlan.advanceSearchParams, mrtype: value}
  }
  roomNameChange = (value) => {
    const {meetingRoomPlan} = this.props;
    this.setState({
      roomName : value
    })
    meetingRoomPlan.advanceSearchParams = {...meetingRoomPlan.advanceSearchParams, roomname: value}
  }

  /*查询会议室使用情况与会议列表*/
  query = (value = this.state.roomName, roomId = '', clearUserMap = true,mrtype=this.state.mrtype) => {
    const {meetingRoomPlan} = this.props;
    let {form, searchFields} = meetingRoomPlan;
    let {timeType} = this.state;
    let newState = {
      roomName: value,
      roomId: roomId,
      mrtype:mrtype
    }
    let params = this.getQueryParams(value,mrtype);
    // meetingRoomPlan.advanceSearchParams = {...meetingRoomPlan.advanceSearchParams, roomname: value}
  
    let advanceSearchParams = {...meetingRoomPlan.advanceSearchParams, roomname: value, mrtype:mrtype};
    //查询其他自定义字段
     let cusSearchDatas={};
     let cusDatas=toJS(searchFields);
     const cusSearchParams = form.getFormParams();
     cusDatas&&cusDatas.length>0&&cusDatas.map(group=>{
         group.items&&group.items.map(item=>{
             for(let key in cusSearchParams){
                 //以前的三个字段不做处理
                 if(key=='roomname'||key=='equipment'||key=='mrtype'||cusSearchParams[key].toString() == ''||key != item.domkey[0]){
                     continue;
                 }
                 const type = item.conditionType.toUpperCase();
                 cusSearchDatas[item.domkey] = cusSearchParams[key];
             }

         });



     });
    advanceSearchParams={...advanceSearchParams,...cusSearchDatas}

    params = {...params, ...advanceSearchParams};
   
    clearUserMap && (newState.useMap = {})
    this.setState(newState)
    // if(type=='advanceSearch'){

    //   // this.setState({
    //   //   roomPlanId:'',
    //   //   roomPlanType:''
    //   // })

    //   params={
    //     ...params,
    //     roomid:''
    //   }

    // }else{
      params={
        ...params,
        mrtype:this.state.roomPlanType?this.state.roomPlanType:params.mrtype,
        roomid:this.state.roomPlanId?this.state.roomPlanId:params.roomid
      }
    // }
    this.queryPageTable(params);
  }
  
  /*根据state与传入的会议室名称生成查询用的参数，既可以给会议室使用情况用，也可以给会议列表用*/
  getQueryParams = (value = this.state.roomName,mrtype=this.state.mrtype) => {
    let {date, subId, timeType} = this.state
    
    let curmoment = moment.isMoment(date) ? date : moment(date)
    let params = {
      roomname: value,
      mrtype: mrtype,
      equipment: '',
      currentdate: curmoment.format('YYYY-MM-DD') || '',
      bywhat: timeType == 'day' ? 4 : timeType == 'week' ? 3 : 2,
      curmoment: curmoment,
    }
    subId && (params.subid = subId)
    return params
  }
  
  /*查询会议列表*/
  queryPageTable (params = {}, clickType) {
    let {getRoomReportList} = this.props.meetingRoomPlan
    let {isFirst} = this.state;
    // let {roomPlanId,roomPlanType} = this.props;
    // if(params.roomid){
      getRoomReportList(params, (sessionkey) => {
        this.setState({pageTabKey: sessionkey})
        if(isFirst){
          setTimeout(this.getRoomReportData(params, clickType),1000)
          this.setState({isFirst:false})
        }else{
          this.getRoomReportData(params, clickType)
        }
        
      })

    // }else{
    //     if (roomPlanId){
    //       params.roomid = roomPlanId
    //     }
    //     getRoomReportList(params, (sessionkey) => {this.setState({pageTabKey: sessionkey})})
    // }
    
  }

  getRoomReportData = (params, clickType)=>{
    let {timeType} = this.state;
    if(clickType === 'click-fliter') return; // 直接点击单个会议室不请求
    Apis.getRoomReportData(params).then(
      result => {
        let duration = (timeType == 'day' && result.dspUnit > 0) ? 60 / result.dspUnit : 0
        let useMap = {}
        result.datas && result.datas.forEach((obj) => {
          if (!obj.roomid) return
          useMap[obj.roomid] = obj.info
        })
        this.setState({
          rooms: result.rooms || [],
          useMap: useMap,
          duration: duration,
          roomLoading: false
        })
      }
    )
  }
  
  /*根据roomId查询会议列表*/
  queryPageTableByRoomId (roomId) {
    let params = this.getQueryParams()
    
    params.roomid = roomId;
    params.mrtype = this.state.mrtype;
    this.queryPageTable(params, 'click-fliter');
  }
  
  render () {
    let {comsWeaTableStore, dragChooseVisible} = this.props.meetingRoomPlan

    // 上方使用的基础数据
    let {timeType, baseLoading, subName, color, date, RoomPlanContainer, meetingId, pageTabKey,weekStartDay} = this.state
    let dataSize = 0;
    // 下方列表的key
    if (comsWeaTableStore[pageTabKey]) {
      let {datas} = comsWeaTableStore[pageTabKey]
      dataSize = datas.length;
    }
    if (baseLoading) {
      return (
        <div className="align-center top40"><Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@l3g2qu`} /></div>
      )
    }
    // 列表中使用的数据
    let {roomLoading, startHour, endHour, rooms, roomId, roomPlanVisible} = this.state
    
    // 新建会议的控制
    let {createObj} = this.state
    
    let {blockNum, tableTitle, tableHeaders} = this.getTableHeaderInfo(timeType, date, startHour, endHour,weekStartDay)
    let blockNumTemp = (timeType=='week' && weekStartDay==1)?7:blockNum;
    const {canCreate} = this.props
    // 会议室使用情况的内容
    let tableContent = (
      <table className="room-plan-tab">
        <tbody>
        
        {!roomLoading && (rooms && rooms.length > 0) &&
        rooms.map((room, index) => {
          let tdList = this.createTdList(room, blockNum, index,weekStartDay)
          let title = createRoomTitle(room.title, room.img,room.id,room.screenShowType)
          let roomTdClass = roomId == room.id ? 'room-name cur' : 'room-name'
          return (
            <tr className={index == 0 ? 'no-border-top' : timeType=="day"&&"room-tr"} roomname={room.name}>

              <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@6fpjjg@${room.id}`} title={title} getTooltipContainer={() => container}
                       overlayClassName="white-tooltip" placement="right">
                <td className={roomTdClass} onClick={this.queryPageTableByRoomId.bind(this, room.id)}>{room.name}</td>
              </Tooltip>
              {tdList}
            </tr>
          )
        })
        }
        </tbody>
      </table>
    )
    
    // 高度控制
    const {tabHeight, listHeight, conHeight, visible, dialogType} = this.state
    let tabHeightValue, listHeightValue
    let listHeightTemp = dataSize*39 + 44 + 40;
    let allTrHeight = 0;
    $('.list-container table').find('tr').each((idx,v)=>{
      allTrHeight = allTrHeight + $(v).height()
    })
    if(dataSize == 0){
      if(tabHeight > conHeight){
        tabHeightValue = conHeight - (39 + 44 + 40)
        listHeightValue = 39 + 44 + 40;
      }else if(tabHeight > (conHeight- (39 + 44 + 40))){
        tabHeightValue = conHeight - (39 + 44 + 40)
        listHeightValue = 39 + 44 + 40;
      }else{
        tabHeightValue = 'auto'
        listHeightValue = 'auto'
      }
    }else if(dataSize > 0 && dataSize < 5){
      if(tabHeight > conHeight){
        tabHeightValue = conHeight * 0.7
        listHeightValue = conHeight * 0.3;
      }else if(tabHeight > (conHeight * 0.6)){
        tabHeightValue = conHeight * 0.6
        listHeightValue = conHeight * 0.4;
      }else{
        tabHeightValue = tabHeight
        listHeightValue = conHeight - tabHeight
      }
    }else if(dataSize >= 5){
      if(tabHeight > conHeight){
        tabHeightValue = conHeight * 0.6
        listHeightValue = conHeight * 0.4;
      }else if(tabHeight > (conHeight * 0.6)){
        tabHeightValue = conHeight * 0.6
        listHeightValue = conHeight * 0.4
      }else{
        tabHeightValue = tabHeight
        listHeightValue = conHeight - tabHeight
      }
    }

    // 下面会议list的高度由上面会议室的多少控制
    let roomCounts = rooms && rooms.length || 0;
    let weaMeetingRoomplanContainer = this.refs.weaMeetingRoomplanContainer ? $(this.refs.weaMeetingRoomplanContainer).height() - 108 : 400;
    let roomsHeight = weaMeetingRoomplanContainer * 0.6, meetingsListHeight = weaMeetingRoomplanContainer * 0.4;
    if(roomCounts > 0) {
      let roomTrHeight = $('.tab-container .room-tr').height() || 30; // 每个会议tr的高度
      if(roomTrHeight*roomCounts < roomsHeight) {
        roomsHeight = (roomTrHeight + 1)*roomCounts;
        meetingsListHeight = weaMeetingRoomplanContainer - roomsHeight;
      }
    }

    let startTime = (startHour > 9 ? startHour : '0' + startHour) + ':00',
    endTime = (endHour > 9 ? endHour : '0' + endHour) + ':59';
    let roomSearchProps = {
      mrtype: this.state.mrtype,
      mrtypeChange: this.mrtypeChange,
      roomPlanId: this.state.roomPlanId,  
      roomPlanType: this.state.roomPlanType,
      roomName: this.state.roomName,
      roomNameChange: this.roomNameChange,
      query: this.query,
      getQueryParams: this.getQueryParams,
    };
    let roomplanTopBox = () => (
      <div className="room-plan-top">
        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@hhlo9h`} className="room-plan-top-con line" {...roomSearchProps}>
            <span className="meeting-room-organization" onClick={() => {
              typeof this.props.showLeftTree === 'function' && this.props.showLeftTree();
            }} style={{ paddingRight: '15px',display:'inline-block',height:'100%','max-width': 200,overflow:'hidden','text-align': 'left','text-overflow':'ellipsis','white-space':'nowrap','vertical-align':'middle'}} title={subName}>{subName}</span>
          <WeaDateSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaDateSwitch@atlnpq`} 
            onChange={this.onChangeWeaDateSwitch} 
            currentDay={date} 
            currentType={timeType}
            datePickerProps={{locale:{firstDayOfWeek:weekStartDay}}} 
            weekFirstDay={weekStartDay} 
            ref={'weaDateS'}
            C_N={weekStartDay == 0 ? false:true}/>
          <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@ai8ysj`} placement="bottom" key="meeting-room-refresh" title={getLabel(354,"刷新")}>
            <span className="icon-coms-Refresh" style={{
              cursor: 'pointer', padding: '0 10px', color: '#B2B2B2',
              fontSize: '16px', display: 'inline-block', position: 'absolute', top: '15px'
            }}
                  onClick={() => { this.setState({roomLoading: true}, this.query) }}/>
          </Tooltip>
          <div className="legend">
            <div style={{marginRight: '3px'}} title={getLabel(383468,"占用")}>
              <div className="square" style={{backgroundColor: color.usedColor}}/>
              <div className='squareName'>{getLabel(383468,"占用")}</div>
            </div>
            <div style={{marginRight: '3px'}} title={getLabel(2242,"待审批")}>
              <div className="square" style={{backgroundColor: color.agreementColor}}/>
              <div className='squareName'>{getLabel(2242,"待审批")}</div>
            </div>
            <div title={getLabel(127867,"冲突")}>
              <div className="square" style={{backgroundColor: color.conflictedColor}}/>
              <div className='squareName'>{getLabel(127867,"冲突")}</div>
            </div>
          </div>
        </Row>
  
        {/* 会议室使用情况的头部 */}
        <table className="room-plan-tab-header">
          <tbody>
          <tr className="no-border-top">
            <th className="first align-center">{getLabel(383473,"会议室")}</th>
            <th colSpan={blockNumTemp}>{tableTitle || `${getLabel(383375,"读取中")}...`}</th>
          </tr>
          {tableHeaders && tableHeaders.length > 0 && (
            <tr>
              <th className="search">
                <span style={{ display: 'inline-block', width:"calc(100% - 25px)" }}>
                  <WeaInputSearch ecId={`${this && this.props && this.props.ecId || ''}_WeaInputSearch@gsa1za`}
                    value = {this.state.roomName}
                    style={this.state.roomPlanId?{width:"100%", paddingLeft: 0, height: "100%"}:{display: 'inline-block',borderRight: '1px solid #eaeaea'}}
                    placeholder={getLabel(82892,"搜索会议室")}
                    onSearch={(v) => this.query(v)}
                    onSearchChange = {this.roomNameChange}
                  />
                </span>
                {!this.state.roomPlanId && <LeftSearch ecId={`${this && this.props && this.props.ecId || ''}_LeftSearch@qn0yxq`} mrtype={this.state.mrtype} mrtypeChange = {this.mrtypeChange} roomPlanId={this.state.roomPlanId}  roomPlanType={this.state.roomPlanType} roomName = {this.state.roomName} roomNameChange = {this.roomNameChange} query = {this.query} getQueryParams = {this.getQueryParams} />}
              </th>
              {tableHeaders.map((header) => {
                return (<th className="header" title={header}>{header}</th>)
              })}
            </tr>
          )}
          </tbody>
        </table>
      </div>
    );
    
    let roomPlanContainerBox = () => (
      <span>
        {roomLoading && <div className="align-center top40"><Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@rz167u`} /></div>}
        {!roomLoading && (!rooms || rooms.length == 0) && (
          <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@kkgpc8`} icon='icon-coms-blank'>
            <div style={{color: '#c5c5c5'}}>{getLabel(383343,"暂无会议室")}</div>
          </WeaAlertPage>
        )}
        
        <div className="tab-container" style={{height: roomsHeight}}>
          <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@ha3sdv`} height="100%" ref="tabScroll">
            {/* 会议室使用情况的内容 */}
            {canCreate && timeType == 'day' ? (
              dragChooseVisible && <WeaDragChoose ecId={`${this && this.props && this.props.ecId || ''}_WeaDragChoose@mskdi3`} ref="drag" activeStyle={{backgroundColor: '#E1ECFF'}} onSelectEnd={this.dragChooseEnd}
                              checkActive={this.checkDragActive}>
                {tableContent}
              </WeaDragChoose>
            ) : tableContent}
          </WeaNewScroll>
        </div>

        <div className="list-container" style={{height: meetingsListHeight}} /*ref={(el)=>($(el).find('*').each((idx,v)=>{console.log(v)}))} */>
          {canCreate && timeType == 'day' ? 
            <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@discw9`} {...this.props.WeaRightMenuProps} key={'roomplanRightMenu'}>
              {/* 会议列表 */}
              {rooms && rooms.length > 0 && comsWeaTableStore[pageTabKey] &&
              <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@8zjzqx`} sessionkey={pageTabKey} hasOrder={true} onOperatesClick={this.getOperatesClick }
                        comsWeaTableStore={comsWeaTableStore[pageTabKey]}
                        getColumns={this.getColumns} needScroll={listHeightValue != 'auto'}
                        outerHeight={this.props.height}
                        scroll={{ y: meetingsListHeight - 62 - 60 + 20}}
                        />}
            </WeaRightMenu>
            : 
            (
              rooms && rooms.length > 0 && comsWeaTableStore[pageTabKey] &&
                <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@xypvf2`} sessionkey={pageTabKey} hasOrder={true} onOperatesClick={this.getOperatesClick }
                          comsWeaTableStore={comsWeaTableStore[pageTabKey]}
                          getColumns={this.getColumns} needScroll={listHeightValue != 'auto'}
                          outerHeight={this.props.height}
                          scroll={{ y: meetingsListHeight - 62 - 60 + 20}}
                          />
            )
          }
        </div>
      </span>
    );
    return (
      <div className="wea-meeting-roomplan-con f12" ref={'weaMeetingRoomplanContainer'}>
        
        {roomplanTopBox()}

        <div className="roomplan-container">
          {canCreate && timeType == 'day' ?  
            roomPlanContainerBox()  
            : 
            <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@214583`} {...this.props.WeaRightMenuProps} key={'roomplanRightMenu'}>
              {roomPlanContainerBox()}
            </WeaRightMenu>
          }
        </div>

        <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@jqvkzz`}
          style={{width: 348, height: 200}}
          className='wea-meeting-roomplan-fast-create'
          visible={this.state.showFastCreateDialog}
          onCancel={() => this.setState({showFastCreateDialog: false})}
        >
          <div className='fast-create'>
            <p className='fast-create-time'>{this.state.createObj.startTime} ～ {this.state.createObj.endTime}</p>
            <input placeholder={`${getLabel(385977,'请输入事由')}...`} onChange={e => this.setState({name: e.target.value})}/>
            <p className='fast-create-foot'>
              <span className='foot-left' onClick={() => {
                this.setState({showFastCreateDialog: false});
                this.setShowCreate()}}
              >{getLabel(22045,'详细')}>></span>
              <span className='foot-right'>
                <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@c2iiws`} type='primary' onClick={() => {this.doSubmit();}}>{getLabel(382958,'确定')}</Button>
              </span>
            </p>
          </div>
        </WeaDialog>

        {<MeetingDialog ecId={`${this && this.props && this.props.ecId || ''}_MeetingDialog@knsbvf`}
          setRoomPlan={this.setRoomPlan}
          setDialog={this.setDialog}
          setType={this.setType}
          setMeetingId={this.setMeetingId}
          setAll={this.setAll}
          
          isRoomPlan={true}
          
          type={dialogType}//新建为'create',查看为'preview',编辑edit,会议决议---待定
          visible={visible}//显隐受控
          /* doClose={()=>{close()}}//关闭回调, 保存等按钮会自动调用该回调，可以在这里写一些页面的刷新操作 */
          /* onlyClose={() => { onlyClose() }}//关闭回调,关闭/取消等按钮会自动调用该回调，只做关闭操作 */
          doRefesh={this.doRefesh}//自定义刷新页面，不会关掉弹出框(后半句没用)
          meetingId={meetingId} //会议id，查看会议时用到
          isInterval={false}//新建会议类型，true是周期会议， false是普通会议
          meetingDate={createObj.createDate}//新建日期//1
          begintime={createObj.startTime || startTime}//1
          endtime={createObj.endTime || endTime}//1
          address={createObj.room}//1
          /* zIndex={dialogZIndex}//弹出框高度 */
        
        />}
        {RoomPlanContainer && <RoomPlanDialog ecId={`${this && this.props && this.props.ecId || ''}_RoomPlanDialog@d6117z`}
          setRoomPlan={this.setRoomPlan}
          canCreate={false}
          height={600}
          visible={RoomPlanContainer}/>}
      </div>
    )
  }

  //快速创建会议室的保存方法
  doSubmit = () => {
    const {createObj, name} = this.state;
    const {createDate, startTime, endTime, room} = createObj;
    if(name.split(' ').join('').length == 0){//事由必填校验
      Modal.error({
        title: getLabel(15172,'系统提示'),
        content: getLabel(385977,'请输入事由'),
      });
    }else {
      // this.setState({showFastCreateDialog: false});
      const chkParams = {
        isquick: 1,
        address: room.id,
        begindate: createDate,
        enddate: createDate,
        begintime: startTime,
        endtime: endTime,
        name: this.state.name,
      };
      API_LIST.customMeetingChk(chkParams).then((result) => {
        if(result.chkstatus){
          API_LIST.chkMeeting(chkParams).then((result) => {
            if (!result.address.chkstatus) {
              this.doAddressTip(chkParams, result)
            } else if (!result.member.chkstatus) {
              this.doMemberTip(chkParams, result)
            } else {
              //走提交接口
              this.quickNewMeeting(chkParams)
            }
          })
        }else{
          if(result.isForbidden){
            let _that = this;
            errorModal({
              title: getLabel(15172, '系统提示'),
              content: result.msg,
              onOk() {
                _that.setState({showFastCreateDialog: false});
              }
            })
          }else{
            let _that = this;
            let conflictMsg = (
              <div style={{marginRight: '-20px'}}>
                <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@ocot5p`} height='80px'>
                  {result.msg}
                  {
                    <span>{getLabel(384774, '是否继续申请？')}</span>
                  }
                </WeaNewScroll>
              </div>
            )
            confirm({
              title: getLabel(15172, '系统提示'),
              content: conflictMsg,
              onOk() {
                //走提交接口
                API_LIST.chkMeeting(chkParams).then((result) => {
                  if (!result.address.chkstatus) {
                    _that.doAddressTip(chkParams, result)
                  } else if (!result.member.chkstatus) {
                    _that.doMemberTip(chkParams, result)
                  } else {
                    //走提交接口
                    _that.quickNewMeeting(allCreateDatas)
                  }
                })
              },
              onCancel() {
                _that.setState({showFastCreateDialog: false});
              },
            })
          }
        }
      })
    }
  }

  doAddressTip = (allCreateDatas, result) => {
    let that = this
    let conMsg = result.address.msg.map((e) => {
      return <div>{`[${e}]`}{getLabel(127867, '冲突')}</div>
    })
    let conflictMsg = (
      <div style={{marginRight: '-20px'}}>
        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@hhhous`} height='80px'>
          {conMsg}
          {
            <span>{getLabel(384774, '是否继续申请？')}</span>
          }
        </WeaNewScroll>
      </div>
    )
    if (result.address.cansub == true) {//冲突了是否可提交，true是可提交
      confirm({
        title: getLabel(384773, '会议室冲突'),
        content: conflictMsg,
        onOk() {
          if (!result.member.chkstatus) {
            that.doMemberTip(allCreateDatas, result)
          } else {
            //走接口
            that.quickNewMeeting(allCreateDatas)
          }
        },
        onCancel() {
          that.setState({showFastCreateDialog: false});
        },
      })
    } else {
      errorModal({
        title: getLabel(32875, '会议室冲突不能提交'),
        content: conMsg,
        onOk() {
          that.setState({showFastCreateDialog: false});
        }
      })
    }
  }

  doMemberTip = (allCreateDatas, result) => {
    let that = this
    let conflictMsg = '';
    let cont = result.member.msg.hrms.map((e) => {
      return <div>{e}</div>
    })
    let contcrms = result.member.msg.crms.map((e) => {
      return <div>{e}</div>
    })
    conflictMsg = (
      <div style={{marginRight: '-20px'}}>
        <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@q3we5r`} height='80px'>
          {
            result.member.msg.hrms.length > 0 ? getLabel(30042, '人员') + '：' : ''
          }
          {cont}
          {
            result.member.msg.crms.length > 0 ? getLabel(136, '客户') + '：' : ''
          }
          {contcrms}
          {
            result.member.cansub == true ?
              <span>{getLabel(384774, '是否继续申请？')}</span>
              :
              <span>{getLabel(32874, '不能提交！')}</span>
          }
        </WeaNewScroll>
      </div>
    )
    if (result.member.cansub == true) {
      confirm({
        title: getLabel(384775, '参会人员冲突'),
        content: conflictMsg,
        onOk() {
          //走提交接口
          that.quickNewMeeting(allCreateDatas)
        },
        onCancel() {
          that.setState({showFastCreateDialog: false});
        },
      })
    } else {
      errorModal({
        title: getLabel(384776, '参会人员冲突不能提交'),
        content: conflictMsg,
        onOk() {
          that.setState({showFastCreateDialog: false});
        },
        onCancel() {
          that.setState({showFastCreateDialog: false});
        },
      })
    }

  }

  quickNewMeeting = (params) => {
    Apis.newMeeting(params).then(result => {
      if(result.status){
        this.doRefesh();
      }else {
        message.error(getLabel(386470,'新建会议失败！'))
      }
    })
    //快速新建完，要清空state的name
    this.setState({name: '',showFastCreateDialog: false})
  }

  /*周月日组件切换回调 */
  onChangeWeaDateSwitch = (type, date, range) => {
    type != this.state.timeType && this.setState({timeType: type}, this.query)
    let dateClone = moment(date)//克隆date
    let stateDate = moment.isMoment(this.state.date) ? this.state.date : moment(this.state.date)
    dateClone.format('YYYY-MM-DD') != stateDate.format('YYYY-MM-DD') && this.setState({date: dateClone.toDate()}, this.query)
  }
  setAll = (meetingId, bool, type) => {
    this.setState({
      meetingId: meetingId,
      visible: bool,
      dialogType: type
    })
  }
  setMeetingId = (meetingId) => {
    this.setState({meetingId: meetingId})
  }
  setRoomPlan = (bool) => {
    this.setState({RoomPlanContainer: bool})
  }
  setDialog = (bool) => {
    this.setState({visible: bool})
  }
  setType = (type) => {
    this.setState({dialogType: type})
  }
  setDialogZIndex = (index) => {
    this.setState({
      dialogZIndex: index
    })
    
  }

  /*关闭新建会议的回调*/
  doRefesh = () => {
    this.setState({
      createObj: {},
    }, this.query(this.state.roomName, this.state.roomId, false))
    
  }
  
  /*获得会议室使用情况的头部*/
  getTableHeaderInfo = (timeType, date, startHour, endHour,weekStartDay) => {
    let blockNum = 0,initWeekI = 0, tableTitle = '', tableHeaders = []
    let curmoment = moment.isMoment(date) ? date : moment(date)
    if (timeType == 'day') {
      blockNum = endHour - startHour + 1
      tableTitle = curmoment.format(i18n.moment.dateformat.Md3)+' '+getLabel(33425,"单位")+':'+getLabel(383376,"时")
      let weekNum = curmoment.weekday ? curmoment.weekday() : curmoment;
      tableTitle = this.formatShowWeek(tableTitle, 'day', weekNum);
      for (startHour; startHour <= endHour; startHour++)
        tableHeaders.push(startHour);
    } else if (timeType == 'week') {
      weekStartDay == 1?blockNum = 8 : blockNum = 7
      weekStartDay == 1?initWeekI = 1 : initWeekI = 0
      //为什么注释下面：在每年的最后一周计算第几周的时候，会计算成当前01周，有问题
      // tableTitle = curmoment.format(i18n.moment.dateformat.y4w2)
      
      let localeKey = 'e9_locale';
      let langId= 7;
      try{
          langId=(window.localStorage&& window.localStorage.login) ? (JSON.parse(window.localStorage.login)?JSON.parse(window.localStorage.login).langId:7) :7;
      }catch(e){}

      let language = langId||(window[localeKey]&&window[localeKey].userLanguage)||7;
      if(language==7){
        tableTitle = curmoment.format(i18n.moment.dateformat.y4) + this.getWeekOfYear(weekStartDay,date) + '周'
      }else if(language==9){
        tableTitle = curmoment.format(i18n.moment.dateformat.y4) + this.getWeekOfYear(weekStartDay,date) + '周'
      }else if(language==8){
        tableTitle = curmoment.format(i18n.moment.dateformat.y4) +'[W]' + this.getWeekOfYear(weekStartDay,date) 
      }

      for (var i = initWeekI; i < blockNum; i++) {
        // console.log('curmoment.day>>>',i+'  '+weekStartDay == 1?curmoment.isoWeekday(i).format(i18n.moment.dateformat.Md3):curmoment.day(i).format(i18n.moment.dateformat.Md3))
        let tableHeader = weekStartDay == 1?curmoment.isoWeekday(i).format(i18n.moment.dateformat.Md3):curmoment.day(i).format(i18n.moment.dateformat.Md3);
        let currentDate = weekStartDay == 1 ? curmoment.isoWeekday(i) : curmoment.day(i);
        let weekNum = currentDate.weekday ? currentDate.weekday() : currentDate;
        tableHeader = this.formatShowWeek(tableHeader, 'week', weekNum);
        tableHeaders.push(tableHeader)
      }
    } else {
      blockNum = curmoment.daysInMonth()
      tableTitle = curmoment.format(i18n.moment.dateformat.yM) + ` (${blockNum}${getLabel(383378,"天")})`
      for (var i = 1; i <= blockNum; i++)
        tableHeaders.push(i);
    }
    return {blockNum: blockNum, tableTitle: tableTitle, tableHeaders: tableHeaders}
  }

  getWeekOfYear = (weekStartDay,date)=>{
    var today = new Date(date);
    var firstDay = new Date(today.getFullYear(),0, 1);
    var dayOfWeek = firstDay.getDay(); //获得周的第几天，0代表周日
    var spendDay= 1;
    if(weekStartDay == 1){//周一开始
      if (dayOfWeek !=0 ) {
          spendDay=7-dayOfWeek+1;//获取第二周的开始星期
        }
    }else if(weekStartDay == 0){//周日开始
      if (dayOfWeek == 0 ) {
        spendDay=7;//获取第二周的开始星期
      }else{
        spendDay=7-dayOfWeek;
      }
    }
    
    firstDay = new Date(today.getFullYear(),0, 1+spendDay);//获取周的第一天
    var d =Math.ceil((today.valueOf()- firstDay.valueOf())/ 86400000);
    var result =Math.ceil(d/7);
    if((result +1)<10){
      result = '0'+(result+1)
    }else{
      result = result + 1;
    }
    return result;
  }; 

  formatShowWeek = (tableTitle, type, weekNum)=>{
    let shortWeekdays =  [getLabel(16106,"周日"), getLabel(16100,"周一"), getLabel(16101,"周二"), getLabel(16102,"周三"), getLabel(16103,"周四"), getLabel(16104,"周五"),
    getLabel(16105,"周六")];
    const languageidweaver = localStorage.languageidweaver;
    if(languageidweaver === '7') { // 中文模式下
      if(type === 'week') {
        if(typeof weekNum === 'number'){
          if(typeof tableTitle === 'string') {
            const dateStr = tableTitle.split(' ');
            tableTitle = `${dateStr[0]} (${shortWeekdays[weekNum]})`;
          }
        }
      } else if(type === 'day') {
        const dateStr = tableTitle.split(' ');
        tableTitle = `${dateStr[0]} (${shortWeekdays[weekNum]}) ${dateStr[2]}`;
      }
      return tableTitle;
    }else{
      return tableTitle;
    }
  }
  
  /*获得会议列表的列定义*/
  getColumns = (e) => {
    let newColumns = ''
    newColumns = e.map(column => {
      let newColumn = column
      newColumn.render = (text, record, index) => { //前端元素转义
        let valueSpan = record[newColumn.dataIndex + 'span'] !== undefined ? record[newColumn.dataIndex + 'span'] : record[newColumn.dataIndex]
        return (
          newColumn.dataIndex == 'name' ? <div><a className="wea-url-name" style={{cursor: 'pointer'}} onClick={() => {
            this.setState({visible: true, dialogType: 'preview', meetingId: record.id})
            record.status&&record.status=='0'&&record.meetingstatus=='2'&&setTimeout(()=>this.query(),3000) ;
          }} dangerouslySetInnerHTML={{__html: valueSpan}}/> {record.status&&record.status=='0'&&record.meetingstatus=='2'&&<span class="icon-coms02-new" style={{fontSize:'22px'}} ><span class="path1"></span><span class="path2"></span><span class="path3"></span><span class="path4"></span></span>}</div>
            : <div className="wea-url" dangerouslySetInnerHTML={{__html: valueSpan}}/>
        
        )
      }
      return newColumn
    })
    return newColumns
  }
  
  /*创建会议，内含冲突判断*/
  openCreateMeeting = (room, startTime, endTime, conflict) => {
    let {date, roomConflictType} = this.state
    // 是否可新建
    const {canCreate} = this.props
    let canCreate1= this.props.meetingCalView.canCreate
    if (!canCreate)return;
    if(!canCreate1) return;
    
    if (conflict) {
      if (roomConflictType == 2) {
        Modal.error({content: getLabel(383344,"该会议室已有会议安排，不能申请会议")})
        return
      } else if (roomConflictType == 1) {
        // let that = this
        Modal.confirm({
          content: getLabel(383474,"会议起止时间内会议室使用冲突，是否继续申请？"),
          onOk: () => {
            this.openCreateMeetingDialog(date, startTime, endTime, room, true)
            // that.openCreateMeetingDialog(date, startTime, endTime, room, true)
          }
        })
        return
      }
    }else{
      this.openCreateMeetingDialog(date, startTime, endTime, room, true)
    }
  }
  
  /*创建会议，直接打开*/
  openCreateMeetingDialog = (date, startTime, endTime, room, fastCreate = false) => {
    let curmoment = moment.isMoment(date) ? date : moment(date)
    let createDate = curmoment.format('YYYY-MM-DD')
    let createObj = {
      createDate: createDate,
      startTime: startTime,
      endTime: endTime,
      room: room
    }
    let canQuickCreate=this.state.canQuickCreate;

    this.setState({createObj: createObj});
    if(fastCreate && canQuickCreate=='1'){
      this.setState({
        showFastCreateDialog: true,
      })
    }else {
    let { onlyFlowCreate, hideCreateEntry, workflowBaseIds,requestFieldIds } = this.state;
    let curmoment = moment(date).format("YYYY-MM-DD");
    if(hideCreateEntry == 1){
      return;
    }else{
      let workflowBaseIdsArr = [];
      if(workflowBaseIds != ''){
        workflowBaseIdsArr = workflowBaseIds.split(',')
      }
      if(onlyFlowCreate == 1 && hideCreateEntry ==0 && workflowBaseIdsArr.length == 1 ){
        let urlParamsTemp = [];
        requestFieldIds&&Object.keys(requestFieldIds).map((item)=>{
          if(item == 'begindate'){
            requestFieldIds.begindate&&requestFieldIds.begindate.map(item1=>{
              createDate&&urlParamsTemp.push(`&${item1}=${createDate}`)
            })
          }
          if(item == 'begintime'){
            requestFieldIds.begintime&&requestFieldIds.begintime.map(item1=>{
              startTime&&urlParamsTemp.push(`&${item1}=${startTime}`)
            })
          }
          if(item == 'enddate'){
            requestFieldIds.enddate&&requestFieldIds.enddate.map(item1=>{
              createDate&&urlParamsTemp.push(`&${item1}=${createDate}`)
            })
          }
          if(item == 'endtime'){
            requestFieldIds.endtime&&requestFieldIds.endtime.map(item1=>{
              endTime&&urlParamsTemp.push(`&${item1}=${endTime}`)
            })
          }
          if(item == 'address'){
            requestFieldIds.address&&requestFieldIds.address.map(item1=>{
              room&&urlParamsTemp.push(`&${item1}=${room.id}`)
            })
          }
          if(item == 'beginDateTime'){
            requestFieldIds.beginDateTime&&requestFieldIds.beginDateTime.map(item1=>{
              createDate&&startTime&&urlParamsTemp.push(`&${item1}=${createDate} ${startTime}`)
            })
          }
          if(item == 'endDateTime'){
            requestFieldIds.endDateTime&&requestFieldIds.endDateTime.map(item1=>{
              createDate&&endTime&&urlParamsTemp.push(`&${item1}=${createDate} ${endTime}`)
            })
          }
        })
        window.open(`/spa/workflow/static4form/index.html#/main/workflow/req?iscreate=1&workflowid=${workflowBaseIds}${urlParamsTemp.join('')}`);
      }else if(onlyFlowCreate == 1 && hideCreateEntry == 0 && workflowBaseIdsArr.length == 0){
        return errorModal({
          title: getLabel(15172, '系统提示'),
          content: getLabel(510148, '系统查找不到新建会议流程！'),
        })
      }else{
        this.setShowCreate();
      }
    }
      
    }
  }

  setShowCreate = () => {
    this.setState({
      meetingId: '',
      dialogType: 'create',
      visible: true,
    })
  }

  /*创建会议室使用情况的每一行td*/
  createTdList = (room, blockNum, rowNum,weekStartDay) => {
    let {timeType, duration, useMap,onlyFlowCreate,hideCreateEntry} = this.state
    let tdList = []
    let useArray = useMap[room.id]
    // 是否可新建
    const {canCreate} = this.props
    let canCreate1= this.props.meetingCalView.canCreate
    // 创建冲突的、带有提示的单元格
    let createTooltipTd = function (obj, otherProps) {
      let {content, bgcolor, fontcolor, title, meetings} = obj
      let meetingIdStr = '';
      for(var i=0;i<meetings.length;i++){
        meetingIdStr+=","+meetings[i]['id']
      }
      if(meetingIdStr.length){
        meetingIdStr=meetingIdStr.substring(1)
      }
      let style = timeType === 'day' ? {backgroundColor: bgcolor, color: fontcolor || '#000', textAlign: 'center',width: `${100/(60/duration)}%`} 
                                      : {backgroundColor: bgcolor, color: fontcolor || '#000', textAlign: 'center'};
      let forbiddenStyle = onlyFlowCreate == 1 && hideCreateEntry==1?{cursor:'not-Allowed'}:{}
        
      if(!canCreate || !canCreate1){
        forbiddenStyle = {cursor:'not-Allowed'}
      }
      let td = (
        <Tooltip ecId={`${this && this.props && this.props.ecId || ''}_Tooltip@7bnf6a`} title={createTitle(title)} placement="bottomRight">
          <td style={style} conflict={true} {...otherProps} meetingid = {meetingIdStr}>
            <div className="roomplan-td-modal"/>
            {content > 1 && content}</td>
        </Tooltip>
      )
      return td
    }
    if (timeType == 'week' || timeType == 'month') {
      if(timeType == 'week' && weekStartDay == 1){
        let initWeekI = 0;
        blockNum = 8;
        weekStartDay == 1?initWeekI = 1 : initWeekI = 0
        for (let i = weekStartDay; i < blockNum; i++) {
          tdList.push(<td style={{cursor:'not-Allowed'}}>
            <div className="roomplan-td-modal"/>
          </td>)
        }
      }else{
        for (let i = 0; i < blockNum; i++) {
          tdList.push(<td style={{cursor:'not-Allowed'}}>
            <div className="roomplan-td-modal"/>
          </td>)
        }
      }
      
      if (!useArray || useArray.length == 0) {
        return tdList
      }
      useArray.forEach((obj) => {
        // let tdIdx = timeType == 'week' ? moment(obj.date).day() : moment(obj.date).date();
        
        let tdIdx = timeType == 'month' ? (moment(obj.date).date() - 1) : (timeType == 'week' ? weekStartDay == 1?moment(obj.date).isoWeekday():moment(obj.date).day() : moment(obj.date).date())
        timeType == 'week' && weekStartDay == 1 && (tdIdx = tdIdx -1)
        if (tdIdx < 0 || tdIdx >= blockNum) return
        tdList[tdIdx] = createTooltipTd(obj)
      })
      return tdList
    } else {
      return this.createTdListInDay(duration, useArray, room, createTooltipTd, rowNum, tdList)
    }
    
  }
  
  /*创建时间类型为天时的单元格*/
  createTdListInDay (duration, useArray, room, createTooltipTd, rowNum, tdList) {
    let {startHour, endHour, timeType,onlyFlowCreate,hideCreateEntry} = this.state

    let useBlockMap = {}//已被使用的块，数据结构：小时数:{变色的序号：{背景颜色，字体颜色，内容}，...}
    let subNum = duration == 0 ? 1 : Math.floor(60 / duration)//每小时会被分成几段
    
    // 生成已被占用的时间段
    useArray && useArray.forEach((obj) => {
      // 时间处理，确认序号
      if (!obj.time) return
      let time = obj.time.split(':')
      if (time.length != 2) return
      let hour = parseInt(time[0]), minute = parseInt(time[1])
      let idx = duration > 0 ? Math.floor(minute / duration) : 0
      // 找到该数据对应的存储位置。
      if (!useBlockMap[hour]) useBlockMap[hour] = {}
      let useHour = useBlockMap[hour]
      useHour[idx] = obj
    })
    
    let style = timeType === 'day' ? {width: `${100/(60/duration)}%`} : {};
    let forbiddenStyle = onlyFlowCreate == 1 && hideCreateEntry==1?{cursor:'not-Allowed'}:{}
    // 是否可新建
    const {canCreate} = this.props
    let canCreate1= this.props.meetingCalView.canCreate
    if(!canCreate || !canCreate1){
      forbiddenStyle = {cursor:'not-Allowed'}
    }
    /*创建每小时内的分隔块、即第二层td的方法*/
    let createSubTd = (hour, idx, rowNum, colNum) => {
      let startMinute = idx * duration, endMinute = startMinute + duration - 1
      let startTime = (hour > 9 ? hour : '0' + hour) + ':' + (startMinute > 9 ? startMinute : '0' + startMinute),
        endTime = (hour > 9 ? hour : '0' + hour) + ':' + (endMinute > 9 ? endMinute : '0' + endMinute)
      // 有值则说明已被占用
      if (useBlockMap[hour] && useBlockMap[hour][idx]) {
        return createTooltipTd(useBlockMap[hour][idx], {
          itemPosition: [rowNum, colNum],
          startTime,
          endTime,
          room
        })
      }
      // 空时段
      return (
        <td itemPosition={[rowNum, colNum]} {...{startTime, endTime, room}} roomid={room.id} style={{...style,...forbiddenStyle}}>
          <div className="roomplan-td-modal"/>
        </td>
      )
    }
    
    // 生成第一层td列表
    let colNum = 0
    for (startHour; startHour <= endHour; startHour++) {
      let subTdList = []
      for (let i = 0; i < subNum; i++) {
        subTdList.push(createSubTd(startHour, i, rowNum, colNum))
        colNum++
      }
      let td = (
        <td>
          <table className="roomPlan-subTable">
            <tr>{subTdList}</tr>
          </table>
        </td>
      )
      tdList.push(td)
    }
    
    return tdList
  }
  
  /*会议列表的操作栏*/
  getOperatesClick = (record, index, operate, flag) => {
    let meetingid = record.id
    let operateType = operate.index//根据后台接口操作按钮显示顺序确定操作类型 0取消 1提前结束
    if (operateType == 0) {
      Apis.cancelMeeting({meetingid: meetingid}).then((result) => {
        this.query()
      })
      
    } else if (operateType == 1) {
      Apis.overMeeting({meetingid: meetingid}).then((result) => {
        this.query()
      })
    }
  }
  
  /*拖曳结束*/
  dragChooseEnd = (dragState, activeCellProps) => {
    let {startProps = {}, endProps = {}} = dragState, {room} = startProps
    if (!room || !activeCellProps || activeCellProps.length == 0) return
    let conflict = activeCellProps.some((props) => props.conflict)
    let startTime = startProps.startTime;
    let endTime = endProps.endTime;
    if(endTime < startTime){
      this.openCreateMeeting(room, endProps.startTime, startProps.endTime, conflict)
    }else{
      this.openCreateMeeting(room, startProps.startTime, endProps.endTime, conflict)
    }
    this.refs.drag.clear && this.refs.drag.clear()
  }
  
  /*判断拖拽中的每个块是否激活*/
  checkDragActive = (itemProps, dragState) => {
    let {room, itemPosition} = itemProps, {startProps = {}} = dragState, startRoom = startProps.room || {}
    let {onlyFlowCreate,hideCreateEntry} = this.state
    if(onlyFlowCreate == 1 && hideCreateEntry==1) return false;
    if (startRoom.id && room.id == startRoom.id) {
      let {minRow, minColumn, maxRow, maxColumn} = dragState
      return itemPosition[0] >= minRow && itemPosition[0] <= maxRow && itemPosition[1] >= minColumn && itemPosition[1] <= maxColumn
    }
    return false
  }
  
  updateScroll = () => {
    this.refs.tabScroll && this.refs.tabScroll.update()
  }
}

/*获得时间类型的DOM*/
// const getTimeTypeSpan = function(timeType, curType, func) {
//     let timeTypeLabel;
//     switch(timeType) {
//         case 'day': timeTypeLabel = '日';break;
//         case 'week': timeTypeLabel = '周';break;
//         case 'month':timeTypeLabel = '月';break;
//         default:timeType = 'month';timeTypeLabel = '月';break;
//     }
//     return (
//         <span className={curType == timeType ? 'cur' : ''} onClick={func.bind(this, timeType)}>{timeTypeLabel}</span>
//     );
// };
/*创建会议室的提示信息，含会议室图片，以及其它提示说明*/
const createRoomTitle = function (titleList, img,id,showScreen) {
  const iconStyle = {
    display: 'inline-block',
    color: '#58A0F8',
    fontSize: '16px',
    paddingRight: '8px',
    cursor: 'pointer',
    float: 'right',
  };
  let tipArr = []
  tipArr.push(<div>
    {img.length === 0 ? 
        <img src={'/images/ecology9/meeting/no_img_wev9.png'} style={{width: 210, height: 140}}/>
      : 
        <Carousel ecId={`${this && this.props && this.props.ecId || ''}_Carousel@x6ae07@${id}`}>
          {img instanceof Array && img.map(res => {
            return <img src={res} style={{width: 210, height: 140}}/>
          })}
        </Carousel>
      }
  </div>)
  if (Array.isArray(titleList) && titleList.length > 0) {
    tipArr = tipArr.concat(titleList.map((tip,index) => { return <div style={{display:(titleList.length==index+1)&&showScreen?'flex':'',flexWrap:'nowrap'}}><div style={{width:(titleList.length==index+1)&&showScreen?'90%':'100%'}}>{tip}</div> {(titleList.length==index+1)&&showScreen&&<div><span title={getLabel(507119,'会议室使用情况大屏显示')} className="icon-coms-Big-screen-sign" style={iconStyle} 
    onClick={() => { previewScreen(id) }} /></div> }</div>}))
  }
  // tipArr.push(<div><span className="icon-coms-Big-screen-sign" style={iconStyle} onClick={() => { console.log('123') }} /></div>)
  return <div style={{width: 210}}>{tipArr}</div>
}

const previewScreen= function(id){
  window.open(`/spa/meeting/static4engine/engine.html#/meetingengine/screen/${id}`)
}

/*创建会议的提示信息*/
const createTitle = function (titleList) {
  if (Array.isArray(titleList) && titleList.length > 0) {
    return (
      <div className="wea-roomplan-titletip">
        {titleList.map((meet, idx) => {
          return (
            <div>
              {meet.map((tip) => <div>{tip}</div>)}
              {idx + 1 < titleList.length && <div className="line"/>}
            </div>
          )
        })}
      </div>
    )
  }
  return undefined
}

const searchPageTable = (sessionKey) => {
  return (dispatch) => {
    dispatch(WeaTableAction.getDatas(sessionKey, 1))
  }
}

RoomPlanContainer.defaultProps = {
  canCreate: true
}
RoomPlanContainer.propTypes = {
  subId: React.PropTypes.string,//分部id
  subName: React.PropTypes.string,//分部名称
  canCreate: React.PropTypes.bool,//是否可在周期为天时新建
}

export default RoomPlanContainer
